﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Tintuc : System.Web.UI.Page
{
    DADataContext da = new DADataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(Convert.ToString(Request.QueryString["m"])))
            {
                var loaddl = (from a in da.Tintucs where a.Hienthi == 1 orderby a.Matin descending select new { a.Matin, a.Tieude, Tomtat = a.Tomtat.Substring(0, 290) + "...", a.Ngaydang, a.Taikhoan, a.Anhdaidien, a.Alisa }).Skip(0).Take(6);
                dltt.DataSource = loaddl;
                dltt.DataBind();
                htTin.Visible = false;
                pnTin.Visible = true;
                rttin.Visible = false;
                tinlq.Visible = false;
            }
            else
            {
                    tinlq.Visible = true;
                    htTin.Visible = true;
                    pnTin.Visible = false;
                    rttin.Visible = true;
                    string ma = Request.QueryString["m"];
                    var load = (from a in da.Tintucs where a.Matin == int.Parse(ma) && a.Hienthi == 1 select new { a.Tieude, a.Tomtat, a.Noidung, a.Alisa }).FirstOrDefault();
                    tdtin.Text = load.Tieude;
                    tomtat.Text = load.Tomtat;
                    noidung.Text = load.Noidung;
                    var rt = (from b in da.Tintucs where b.Matin != int.Parse(ma) && b.Hienthi == 1 orderby b.Ngaydang descending select new { b.Matin, b.Ngaydang, b.Tieude, b.Alisa }).Skip(0).Take(5);
                    rttin.DataSource = rt;
                    rttin.DataBind();
                
            }

        }
    }
}
